package com.whisper.application.service.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.whisper.common.annotation.Log;
import com.whisper.common.annotation.PageQuery;
import com.whisper.common.core.controller.BaseController;
import com.whisper.common.enums.BusinessType;
import com.whisper.application.service.domain.VrAct;
import com.whisper.application.service.service.IVrActService;
import com.whisper.common.excel.utils.poi.ExcelUtil;

/**
 * 志愿活动Controller
 * 
 * @author whisper
 * @date 2024-01-07
 */
@RestController
@RequestMapping("/service/act")
public class VrActController extends BaseController
{
    @Autowired
    private IVrActService vrActService;

    /**
     * 查询志愿活动列表
     */
    @PageQuery
    @PreAuthorize("@ss.hasPermi('service:act:list')")
    @GetMapping("/list")
    public List<VrAct> list(VrAct vrAct)
    {
        List<VrAct> vrActs = vrActService.selectVrActList(vrAct);
        vrActService.checkAndUpdateStatu(vrActs);
        // 查询更新后的数据
        return vrActService.selectVrActList(vrAct);
    }

    /**
     * 导出志愿活动列表
     */
    @PreAuthorize("@ss.hasPermi('service:act:export')")
    @Log(title = "志愿活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VrAct vrAct)
    {
        List<VrAct> list = vrActService.selectVrActList(vrAct);
        ExcelUtil<VrAct> util = new ExcelUtil<VrAct>(VrAct.class);
        util.exportExcel(response, list, "志愿活动数据");
    }

    /**
     * 获取志愿活动详细信息
     */
    @PreAuthorize("@ss.hasPermi('service:act:query')")
    @GetMapping(value = "/{id}")
    public VrAct getInfo(@PathVariable("id") Long id)
    {
        return vrActService.selectVrActById(id);
    }

    /**
     * 新增志愿活动
     */
    @PreAuthorize("@ss.hasPermi('service:act:add')")
    @Log(title = "志愿活动", businessType = BusinessType.INSERT)
    @PostMapping
    public void add(@RequestBody VrAct vrAct)
    {
        vrActService.insertVrAct(vrAct);
    }

    /**
     * 修改志愿活动
     */
    @PreAuthorize("@ss.hasPermi('service:act:edit')")
    @Log(title = "志愿活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public void edit(@RequestBody VrAct vrAct)
    {
        vrActService.updateVrAct(vrAct);
    }

    /**
     * 删除志愿活动
     */
    @PreAuthorize("@ss.hasPermi('service:act:remove')")
    @Log(title = "志愿活动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public void remove(@PathVariable Long[] ids)
    {
        vrActService.deleteVrActByIds(ids);
    }
}
